package com.wdz.pma.services;

import com.wdz.pma.dao.StudentRepository;
import com.wdz.pma.entities.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Service
public class StudentService {

    @Autowired
    StudentRepository studentRepository;


//  1.save方法（调用【stuRe】的save方法：保存数据到数据库中
    public Student save(Student student){
        return studentRepository.save(student);
    }
//  2.定义getAll方法：调用【stuRe】中的findAll方法
    public List<Student> getAll(){
        return studentRepository.findAll();
    }

    public Student findByStudentId(long theId) {

        return studentRepository.findByStudentId(theId);
    }

    public void delete(Student theStudent) {

        studentRepository.delete(theStudent);
    }
}
